package com.reflex;

import java.lang.reflect.Method;

public class ReflexDemo02 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        // 创建Person对象
        Person person = new Person();
        System.out.println(person);

        // 获取Person的Class对
        Class<?> aClassPerson = Class.forName("com.reflex.Person");
        // 反射创建Person对象，这里调用的是无参构造器
        Object object = aClassPerson.newInstance();
        // 强制类型转换为Person类型
        //Person object = (Person)aClassPerson.newInstance();
        System.out.println(object);

        // 获取Person类中的所有方法
        Method[] methods = aClassPerson.getMethods();
        System.out.println(methods.length);
        for (Method method : methods) {
            System.out.println(method.getName());
        }
    }
}
